package com.liteng.living;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import tv.danmaku.ijk.media.widget.media.IjkVideoView;

public class MyVideoViewActivity extends AppCompatActivity {
    private IjkVideoView mVideoView;
    private boolean mBackPressed;
    private String mVideoPath;
    private String urls[] = new String[]{
            "rtmp://47.88.54.110/xccRtmps/test",
            "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f30.mp4",
            "rtmp://live.hkstv.hk.lxdns.com/live/hks",// rtmp测试
            "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov",// 国产动画片
            "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8",
            "http://livecdn.ahtv.cn/channels/1502/500.flv/live",
            "rtmp://192.168.1.145/xccRtmps/red5StreamDemo",
            "rtmp://192.168.1.185/live/stream",
            "rtmp://192.168.1.185/live/s1"
    };

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_view);
        //mVideoPath = urls[0];//getIntent().getStringExtra("stream_addr");
        mVideoPath = getIntent().getStringExtra("stream_addr");
        mVideoView = (IjkVideoView) findViewById(R.id.video_view);
        // init player
        IjkMediaPlayer.loadLibrariesOnce(null);
        IjkMediaPlayer.native_profileBegin("libijkplayer.so");
        if (mVideoPath != null) {
            mVideoView.setVideoPath(mVideoPath);
        }
//        mVideoView.setRender();
//        mVideoView.setAspectRatio(IRenderView.AR_ASPECT_FIT_PARENT);
        mVideoView.start();
    }

    public void onBackPressed() {
        mBackPressed = true;
        super.onBackPressed();
    }

    protected void onStop() {
        super.onStop();
        if (mBackPressed || !mVideoView.isBackgroundPlayEnabled()) {
            mVideoView.stopPlayback();
            mVideoView.release(true);
            mVideoView.stopBackgroundPlay();
        } else {
            mVideoView.enterBackground();
        }
        IjkMediaPlayer.native_profileEnd();
    }
}
